<?php

namespace app\common\model\xilujob;

use app\common\model\User;
use think\Model;
use traits\model\SoftDelete;


class Chat extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'xilujob_chat';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'createtime_text',
        'message_text'
    ];
    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? xilujob_time_tran($value) : $value;
    }
    public function getMessageTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['message']) ? $data['message'] : '');
        return in_array($data['type'],[3,4,5,6]) ? json_decode($value,true) : $value;
    }
    public function getTypeList()
    {
        return ['1' => __('文字'), '2' => __('图片'), '3' => __('职位'), '4' => __('投递'), '5' => __('人才'),'6'=>__('邀请面试')];
    }

    public function getIsReadList()
    {
        return ['0' => __('否'), '1' => __('是')];
    }

    // 可见状态:0=正常,1=发送人不可见,2=接收人不可见,3=发送人撤回消息(双方都不可见),4=双方都删除记录(双方都不可见)
    public function getSeeTypeList()
    {
        return ['0' => __('正常'), '1' => __('发送人不可见'), '2' => __('接收人不可见'), '3' => __('发送人撤回消息(双方都不可见)'), '4' => __('双方都删除记录(双方都不可见)')];
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'from_uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function senduser()
    {
        return $this->belongsTo(User::class, 'from_uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function receiveuser()
    {
        return $this->belongsTo(User::class, 'to_uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
